<script language="javascript">
	function themanh()
	{
		slanh=document.tintuc.slanh.value;
		slanh=1+parseInt(slanh);
		document.tintuc.slanh.value=slanh;
		anh="Ảnh " + slanh + ": ";
		div=document.getElementById("themanh");
		br=document.createElement("br");
		div.appendChild(br);
		text=document.createTextNode(anh);
		div.appendChild(text);
		file=document.createElement("input");
		file.type="file";
		file.name="anh" + slanh;
		div.appendChild(file);
	}
	function ktra()
	{
		if(document.tintuc.tieude.value=='')
		{
			alert("Xin vui lòng nhập tiêu đề của tin!");
			document.tintuc.tieude.focus();
			return false;
		}
		else if(document.tintuc.tomluoc.value=='')
		{
			alert("Xin vui lòng nhập tóm lược của tin!");
			document.tintuc.tomluoc.focus();
			return false;
		}
		/*else if=============Kiểm tra nội dung*/
		else
		{
			tintuc.target="";
			if(document.tintuc.danhdau.value!='0')
			{
				//alert("sdfd");
				document.tintuc.target="";
			}
			return true;
		}
	}
	function xoaanh(id,matt,ma,cn)
	{
		showdataday(id,'admin/xoaanh.php?mahinh=' + ma + '&matt=' + matt + '&cn=' + cn);
	}
	function themanhmoi(id,matt,cn)
	{
		document.tintuc.danhdau.value=0;
		document.tintuc.target="upload_target";
		document.tintuc.submit();
		document.tintuc.danhdau.value=1;
		alert("Đã thêm ảnh thành công!");
		showdataday(id,'admin/xoaanh.php?matt=' + matt + '&cn=' + cn);
	}
</script>
	<?php
		$matt=$_GET['matt'];
		//echo $matt;
		$kq=$knoi->queryCsdl("select a.*,tenloai from tintuc a,loaitintuc b where matt='$matt' and a.maloaitt=b.maloaitt");
		$n=mysql_fetch_array($kq);
	?>
	<p>TIN TỨC MỚI</p>
	<form action="home_admin.php" method="post" enctype="multipart/form-data" name="tintuc" onsubmit="return ktra();">
		<table align="center">
			<tr>
				<td class="stylelitle">Loại tin tức:<br /><input type="hidden" name="module" value="capnhatchitiettintuc" />
					<?php
						$loai=$n['maloaitt'];
						$kq=$knoi->queryCsdl("select maloaitt,tenloai from loaitintuc where loai!='$loai'");
					?>
					<select name="maloaitt">
						<option selected="selected" value="<?php echo $n['maloaitt']; ?>"><?php echo $n['tenloai']; ?></option>
						<?php
							while($k=mysql_fetch_array($kq))
							{
						?>
								<option value="<?php echo $k['maloaitt']; ?>"><?php echo $k['tenloai']; ?></option>
						<?php
							}
						?>
					</select>				</td>
			</tr>
			<tr>
				<td class="stylelitle">Tiêu đề:<br /><textarea name="tieude" cols="40" rows="2"><?php echo $n['tieude']; ?></textarea></td>
			</tr>
			<tr>
				<td class="stylelitle">Tóm lược:<br />
			    <textarea name="tomluoc" cols="40" rows="3"><?php echo $n['tomluoc']; ?></textarea></td>
			</tr>
			<tr>
			  <td class="stylelitle">Nội dung:<br /><textarea name="noidung" id="idnoidung" cols="20" rows="3"><?php echo $n['noidung']; ?></textarea>
		      <?php
					$CKEditor = new CKEditor();
					$CKEditor->basePath = 'ckeditor/';
					$CKEditor->replace("idnoidung");
				?></td>
			</tr>
			<script type="text/javascript" language="javascript">
   				 ckeditor.replace( 'idnoidung' );
			</script>
			<tr>
				<td class="stylelitle"><!--Ngày đăng:-->Trạng thái:<!--<input type="text" name="ngaydang" maxlength="10" />&nbsp;&nbsp;&nbsp;&nbsp;-->
				<?php
					if($n['trangthai']==1)
					{
				?>
				<input type="radio" name="trangthai" value="1" checked="checked" />&nbsp;Đăng tin&nbsp;&nbsp;&nbsp;<input type="radio" name="trangthai" value="0" />&nbsp;Lưu
				<?php
					}
					else
					{
				?>
				<input type="radio" name="trangthai" value="1"  />&nbsp;Đăng tin&nbsp;&nbsp;&nbsp;<input type="radio" name="trangthai" value="0" checked="checked" />&nbsp;Lưu
				<?php
					}
				?>				</td></tr>
			<tr>
				<td><!--Ngày đăng:--><label class="stylelitle">Ảnh kèm theo:</label>
			<div id="anhkemtheo" style="padding-left:40px;">
			<?php
				$t=$knoi->queryCsdl("select mahinh,duongdan from hinhanh where matt='$matt'");
				$i=1;
				while($l=mysql_fetch_array($t))
				{
					if($i!=1)
					{
				?>
						<br><?php echo $i.". ".$l['duongdan']; ?>&nbsp;<img src="images/Sign-Error-icon1.png" border="0" class="class1" title="Xóa ảnh" onclick="xoaanh('anhkemtheo','<?php echo $matt; ?>','<?php echo $l['mahinh']; ?>','xoa')">
				<?php
				}
					else
					{
				?>
						<?php echo $i.". ".$l['duongdan']; ?>&nbsp;<img src="images/Sign-Error-icon1.png" border="0" class="class1" title="Xóa ảnh" onclick="xoaanh('anhkemtheo','<?php echo $matt; ?>','<?php echo $l['mahinh']; ?>','xoa')">
				<?php
				}
				$i++;
			}
			?>
			</div>
			<!--<img src=images/Sign-Error-icon1.png' border='0' title='Xóa ảnh' onclick='xoaanh('anhkemtheo','".$l['mahinh']."')'>-->
			<!--<br />Ảnh: <input type="file" name="anh" />
			</div><iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>-->
			<div id="themanh" style="padding-left:40px;">
				Ảnh 1: <input type="file" name="anh1" />
			</div>			</td></tr>
			<tr><td style="padding-left:150px;"><input type="button" class="button" name="them" value="Thêm ảnh" onclick="themanh()" />
			  <input type="hidden" name="slanh" value="1" /><input type="hidden" name="matt" value="<?php echo $matt; ?>" /></td></tr>
			</tr>
			<tr><td style="text-align:center"><input type="submit" class="button" value="Cập nhật" />&nbsp;<input class="button" type="reset" value="Hủy bỏ" /></td></tr>
		</table>
	</form>

